﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using CE.Global;
using CE.Admin;

public partial class Admin_home_refinance_AddNewHFVariables : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[CE.Global.General.UserId] != null && Session[CE.Global.General.UserTypeId] != null)
        {
            if (Convert.ToInt32(Session[CE.Global.General.UserTypeId]) !=
                Convert.ToInt32(CE.Global.CEUserType.SiteAdmin))
            {
                Response.Redirect("~/Admin/AdminSecureLogin.aspx");
            }
        }
        else
        {
            Response.Redirect("~/Admin/AdminSecureLogin.aspx");
        }

        if (!IsPostBack)
        {
            //ddlPolicyFrom.StartYear = CE.Global.General.GetUTCDateTime().Year - 2;
            //ddlPolicyFrom.EndYear = CE.Global.General.GetUTCDateTime().Year + 1;
            ddlPolicyFrom.StartYear = CE.Global.General.GetUTCDateTime().Year - 2;
            ddlPolicyFrom.EndYear = CE.Global.General.GetUTCDateTime().Year + 1;

            //ddlPolicyTo.StartYear = CE.Global.General.GetUTCDateTime().Year - 2;
            //ddlPolicyTo.EndYear = CE.Global.General.GetUTCDateTime().Year + 10;
            ddlPolicyTo.StartYear = CE.Global.General.GetUTCDateTime().Year - 2;
            ddlPolicyTo.EndYear = CE.Global.General.GetUTCDateTime().Year + 10;

            EnableDisable();
            //PanelVisible();

            #region Private
            ddlPVTMinLoanTenure.Items.Clear();
            for (int i = 1; i <= 10; i++)
            {
                ddlPVTMinLoanTenure.Items.Add(i.ToString());
            }

            ddlPVTMaxLoanTenure.Items.Clear();
            for (int i = 11; i <= 30; i++)
            {
                ddlPVTMaxLoanTenure.Items.Add(i.ToString());
            }
            ddlPVTMaxLoanTenure.Text = "30";

            ddlPVTMinAgeOfApplicant.Items.Clear();
            for (int i = 18; i <= 30; i++)
            {
                ddlPVTMinAgeOfApplicant.Items.Add(i.ToString());
            }
            ddlPVTMinAgeOfApplicant.Text = "21";

            ddlPVTMaxAgeOfApplicant.Items.Clear();
            for (int i = 31; i <= 70; i++)
            {
                ddlPVTMaxAgeOfApplicant.Items.Add(i.ToString());
            }
            ddlPVTMaxAgeOfApplicant.Text = "65";
            #endregion

            #region HDB
            ddlHDBMinLoanTenure.Items.Clear();
            for (int i = 1; i <= 10; i++)
            {
                ddlHDBMinLoanTenure.Items.Add(i.ToString());
            }

            ddlHDBMaxLoanTenure.Items.Clear();
            for (int i = 11; i <= 30; i++)
            {
                ddlHDBMaxLoanTenure.Items.Add(i.ToString());
            }
            ddlHDBMaxLoanTenure.Text = "30";

            ddlHDBMinAgeOfApplicant.Items.Clear();
            for (int i = 18; i <= 30; i++)
            {
                ddlHDBMinAgeOfApplicant.Items.Add(i.ToString());
            }
            ddlHDBMinAgeOfApplicant.Text = "21";

            ddlHDBMaxAgeOfApplicant.Items.Clear();
            for (int i = 31; i <= 70; i++)
            {
                ddlHDBMaxAgeOfApplicant.Items.Add(i.ToString());
            }
            ddlHDBMaxAgeOfApplicant.Text = "65";
            #endregion

            DataTable _dtCompany = General.GetComboItem("ProviderCompany", false);
            ddlProviderName.DataSource = _dtCompany;
            ddlProviderName.DataTextField = _dtCompany.Columns[0].ColumnName.ToString();
            ddlProviderName.DataValueField = _dtCompany.Columns[1].ColumnName.ToString();
            ddlProviderName.DataBind();

            ClearFields();
            if (Request.Params["hfpid"] != null)
            {
                lblPackageId.Text = Request.Params["hfpid"].ToString();
                ShowHFVariables();
            }
        }
    }

    //protected void ddlLockin_SelectedIndexChanged(object sender, EventArgs e)
    //{
    //    PanelVisible();
    //}


    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            HFVariableDetails _hfvariabledetails = new HFVariableDetails();
            HFVariableDetailsDB _hfvariabledetailsdb = new HFVariableDetailsDB();
            if (lblPVTHFID.Text != string.Empty)
            {
                _hfvariabledetails.PVTHFVariableId = Convert.ToInt64(lblPVTHFID.Text.ToString());
            }
            else
            {
                _hfvariabledetails.PVTHFVariableId = 0;
            }
            if (lblHDBHFID.Text != string.Empty)
            {
                _hfvariabledetails.HDBHFVariableId = Convert.ToInt64(lblHDBHFID.Text.ToString());
            }
            else
            {
                _hfvariabledetails.HDBHFVariableId = 0;
            }
            _hfvariabledetails.HFPackageId = Convert.ToInt64(lblPackageId.Text.ToString());
            _hfvariabledetails.HFProviderId = Convert.ToInt64(ddlProviderName.Text);
            _hfvariabledetails.ProductName = Server.HtmlEncode(General.ClearScriptTag(txtProductName.Text));
            _hfvariabledetails.LoanPurpose = Convert.ToInt16(ddlLoanPurpose.Text);
            _hfvariabledetails.PropertyStatus = Convert.ToInt16(ddlPropertyStatus.Text);
            _hfvariabledetails.InterestRateType = Convert.ToInt16(ddlInterestRatePackage.Text);
            _hfvariabledetails.HasMinimumLoanAmount = chkYes.Checked;
            if(chkYes.Checked)
            {
                _hfvariabledetails.MinimumLoanAmount = Convert.ToSingle(txtMinimumAmount.Text);
            }
            else
            {
                _hfvariabledetails.MinimumLoanAmount = 0.0f;
            }
            _hfvariabledetails.HasPolicyPeriod = chkPolicyPeriod.Checked;
            if(chkPolicyPeriod.Checked)
            {
                _hfvariabledetails.PolicyPeriodFrom = ddlPolicyFrom.GetDate();
                _hfvariabledetails.PolicyPeriodTo = ddlPolicyTo.GetDate();
            }
            else
            {
                _hfvariabledetails.PolicyPeriodFrom =  Convert.ToDateTime("1900-01-01 00:00:00.000");
                _hfvariabledetails.PolicyPeriodTo =  Convert.ToDateTime("1900-01-01 00:00:00.000");
            }
            _hfvariabledetails.LockIn = Convert.ToInt16(ddlLockin.Text);

            if (chkPrivate.Checked)
            {
                _hfvariabledetails.PVTPropertyType = 1;
                _hfvariabledetails.PVTMinLoanTenure = Convert.ToInt32(ddlPVTMinLoanTenure.Text);
                _hfvariabledetails.PVTMaxLoanTenure = Convert.ToInt32(ddlPVTMaxLoanTenure.Text);
                _hfvariabledetails.PVTMinAgeApplicant = Convert.ToInt32(ddlPVTMinAgeOfApplicant.Text);
                _hfvariabledetails.PVTMaxAgeApplicant = Convert.ToInt32(ddlPVTMaxAgeOfApplicant.Text);
                _hfvariabledetails.PVTMaxMarginFin = Convert.ToInt16(ddlPVTMaxMarginFin.Text);
                _hfvariabledetails.PVTFullRedPen = txtPVTFullRedPen.Text.Trim();
                _hfvariabledetails.PVTLegalFeeSubsidy = txtPVTLegalFeeSub.Text.Trim();
                //if (Convert.ToInt16(ddlLockin.Text) == 1)
                //{
                _hfvariabledetails.PVTInterestY1 = Convert.ToSingle(txtPVTInsYear1.Text);
                _hfvariabledetails.PVTDescriptionY1 = txtPVTDesYear1.Text.Trim();
                _hfvariabledetails.PVTInterestY2 = Convert.ToSingle(txtPVTInsYear2.Text);
                _hfvariabledetails.PVTDescriptionY2 = txtPVTDesYear2.Text.Trim();
                _hfvariabledetails.PVTInterestY3 = Convert.ToSingle(txtPVTInsYear3.Text);
                _hfvariabledetails.PVTDescriptionY3 = txtPVTDesYear3.Text.Trim();
                _hfvariabledetails.PVTInterestThereAfter = Convert.ToSingle(txtPVTInsThereAfter.Text);
                _hfvariabledetails.PVTDescriptionThereAfter = txtPVTDesThereAfter.Text.Trim();
                //}
                _hfvariabledetails.PVTMoreInfo = txtPVTMoreInfo.Text.Trim();
                _hfvariabledetails.PVTStatus = chkPVTStatus.Checked;
            }
            else
            {
                _hfvariabledetails.PVTPropertyType = -1;
            }

            if (chkHDB.Checked)
            {
                _hfvariabledetails.HDBPropertyType = 2;
                _hfvariabledetails.HDBMinLoanTenure = Convert.ToInt32(ddlHDBMinLoanTenure.Text);
                _hfvariabledetails.HDBMaxLoanTenure = Convert.ToInt32(ddlHDBMaxLoanTenure.Text);
                _hfvariabledetails.HDBMinAgeApplicant = Convert.ToInt32(ddlHDBMinAgeOfApplicant.Text);
                _hfvariabledetails.HDBMaxAgeApplicant = Convert.ToInt32(ddlHDBMaxAgeOfApplicant.Text);
                _hfvariabledetails.HDBMaxMarginFin = Convert.ToInt16(ddlHDBMaxMarginFin.Text);
                _hfvariabledetails.HDBFullRedPen = txtHDBFullRedPen.Text.Trim();
                _hfvariabledetails.HDBLegalFeeSubsidy = txtHDBLegalFeeSub.Text.Trim();
                //if (Convert.ToInt16(ddlLockin.Text) == 1)
                //{
                _hfvariabledetails.HDBInterestY1 = Convert.ToSingle(txtHDBInsYear1.Text);
                _hfvariabledetails.HDBDescriptionY1 = txtHDBDesYear1.Text.Trim();
                _hfvariabledetails.HDBInterestY2 = Convert.ToSingle(txtHDBInsYear2.Text);
                _hfvariabledetails.HDBDescriptionY2 = txtHDBDesYear2.Text.Trim();
                _hfvariabledetails.HDBInterestY3 = Convert.ToSingle(txtHDBInsYear3.Text);
                _hfvariabledetails.HDBDescriptionY3 = txtHDBDesYear3.Text.Trim();
                _hfvariabledetails.HDBInterestThereAfter = Convert.ToSingle(txtHDBInsThereAfter.Text);
                _hfvariabledetails.HDBDescriptionThereAfter = txtHDBDesThereAfter.Text.Trim();
                //}
                _hfvariabledetails.HDBMoreInfo = txtHDBMoreInfo.Text.Trim();
                _hfvariabledetails.HDBStatus = chkHDBStatus.Checked;
            }
            else
            {
                _hfvariabledetails.HDBPropertyType = -1;
            }
            _hfvariabledetails.RefCEUserId = Convert.ToInt64(Session[General.UserId].ToString());

            _hfvariabledetails.HFPackageId = _hfvariabledetailsdb.Insert(_hfvariabledetails);
            if (_hfvariabledetails.HFPackageId > 0)
            {
                ClearFields();
                lblMessage.Text = "Saved successfully!";
            }
            else
            {
                lblMessage.Text = "Saving failed!";
            }
        }
    }

    protected void btnNew_Click(object sender, EventArgs e)
    {
        ClearFields();
    }

    protected void chkYes_CheckedChanged(object sender, EventArgs e)
    {
        if (chkYes.Checked)
        {
            pnlAmtLimit.Visible = true;
        }
        else
        {
            pnlAmtLimit.Visible = false;
        }
    }

    protected void chkPrivate_CheckedChanged(object sender, EventArgs e)
    {
        EnableDisable();
    }

    protected void chkHDB_CheckedChanged(object sender, EventArgs e)
    {
        EnableDisable();
    }

    protected void chkPolicyPeriod_CheckedChanged(object sender, EventArgs e)
    {
        if (chkPolicyPeriod.Checked)
        {
            pnlPolicyPeriod.Visible = true;
            ddlPolicyFrom.IsEnableValidation(true);
            ddlPolicyTo.IsEnableValidation(true);
        }
        else
        {
            pnlPolicyPeriod.Visible = false;
            ddlPolicyFrom.IsEnableValidation(false);
            ddlPolicyTo.IsEnableValidation(false);
        }
    }

    private void ClearFields()
    {
        //ddlPolicyFrom.StartYear = CE.Global.General.GetUTCDateTime().Year - 2;
        //ddlPolicyFrom.EndYear = CE.Global.General.GetUTCDateTime().Year + 1;
        ddlPolicyFrom.StartYear = CE.Global.General.GetUTCDateTime().Year - 2;
        ddlPolicyFrom.EndYear = CE.Global.General.GetUTCDateTime().Year + 1;

        //ddlPolicyTo.StartYear = CE.Global.General.GetUTCDateTime().Year - 2;
        //ddlPolicyTo.EndYear = CE.Global.General.GetUTCDateTime().Year + 10;
        ddlPolicyTo.StartYear = CE.Global.General.GetUTCDateTime().Year - 2;
        ddlPolicyTo.EndYear = CE.Global.General.GetUTCDateTime().Year + 10;
        lblPVTHFID.Text = "0";
        lblHDBHFID.Text = "0";
        lblPackageId.Text = "0";
        txtProductName.Text = "";
        ddlLoanPurpose.Text = "3";
        ddlPropertyStatus.Text = "3";
        chkPrivate.Checked = false;
        chkHDB.Checked = false;
        chkPrivate.Enabled = true;
        chkHDB.Enabled = true;
        txtPropertyType.Text = "";
        ddlInterestRatePackage.Text = "2";
        chkYes.Checked = false;
        pnlAmtLimit.Visible = false;
        chkPolicyPeriod.Checked = false;
        pnlPolicyPeriod.Visible = false;
        ddlPolicyFrom.IsEnableValidation(false);
        ddlPolicyTo.IsEnableValidation(false);

        ddlLockin.Text = "-1";

        ddlHDBMinLoanTenure.Text = "1";
        ddlHDBMaxLoanTenure.Text = "30";
        ddlHDBMinAgeOfApplicant.Text = "21";
        ddlHDBMaxAgeOfApplicant.Text = "65";
        ddlHDBMaxMarginFin.Text = "90";
        txtHDBFullRedPen.Text = "NONE";
        txtHDBLegalFeeSub.Text = "NONE";
        txtHDBInsYear1.Text = "";
        txtHDBDesYear1.Text = "";
        txtHDBInsYear2.Text = "";
        txtHDBDesYear2.Text = "";
        txtHDBInsYear3.Text = "";
        txtHDBDesYear3.Text = "";
        txtHDBInsThereAfter.Text = "";
        txtHDBDesThereAfter.Text = "";
        txtHDBMoreInfo.Text = "";
        chkHDBStatus.Checked = true;

        ddlPVTMinLoanTenure.Text = "1";
        ddlPVTMaxLoanTenure.Text = "30";
        ddlPVTMinAgeOfApplicant.Text = "21";
        ddlPVTMaxAgeOfApplicant.Text = "65";
        ddlPVTMaxMarginFin.Text = "90";
        txtPVTFullRedPen.Text = "NONE";
        txtPVTLegalFeeSub.Text = "NONE";
        txtPVTInsYear1.Text = "";
        txtPVTDesYear1.Text = "";
        txtPVTInsYear2.Text = "";
        txtPVTDesYear2.Text = "";
        txtPVTInsYear3.Text = "";
        txtPVTDesYear3.Text = "";
        txtPVTInsThereAfter.Text = "";
        txtPVTDesThereAfter.Text = "";
        txtPVTMoreInfo.Text = "";
        chkPVTStatus.Checked = true;

        lblMessage.Text = "";
    }

    private void EnableDisable()
    {
        if (chkPrivate.Checked)
        {
            ddlPVTMinLoanTenure.Enabled = true;
            ddlPVTMaxLoanTenure.Enabled = true;
            ddlPVTMinAgeOfApplicant.Enabled = true;
            ddlPVTMaxAgeOfApplicant.Enabled = true;
            ddlPVTMaxMarginFin.Enabled = true;
            txtPVTFullRedPen.Enabled = true;
            txtPVTLegalFeeSub.Enabled = true;
            txtPVTInsYear1.Enabled = true;
            txtPVTDesYear1.Enabled = true;
            txtPVTInsYear2.Enabled = true;
            txtPVTDesYear2.Enabled = true;
            txtPVTInsYear3.Enabled = true;
            txtPVTDesYear3.Enabled = true;
            txtPVTInsThereAfter.Enabled = true;
            txtPVTDesThereAfter.Enabled = true;
            txtPVTMoreInfo.Enabled = true;
            chkPVTStatus.Enabled = true;

            rfvPVTMinLoanTenure.Enabled = true;
            rfvPVTMaxLoanTenure.Enabled = true;
            rfvPVTMinAgeOfApplicant.Enabled = true;
            rfvPVTMaxAgeOfApplicant.Enabled = true;
            rfvPVTMaxMarginFin.Enabled = true;
            rfvPVTInsYear1.Enabled = true;
            revPVTInsYear1.Enabled = true;
            rfvPVTInsYear2.Enabled = true;
            revPVTInsYear2.Enabled = true;
            rfvPVTInsYear3.Enabled = true;
            revPVTInsYear3.Enabled = true;
            rfvPVTInsThereAfter.Enabled = true;
            revPVTInsThereAfter.Enabled = true;
        }
        else
        {
            ddlPVTMinLoanTenure.Enabled = false;
            ddlPVTMaxLoanTenure.Enabled = false;
            ddlPVTMinAgeOfApplicant.Enabled = false;
            ddlPVTMaxAgeOfApplicant.Enabled = false;
            ddlPVTMaxMarginFin.Enabled = false;
            txtPVTFullRedPen.Enabled = false;
            txtPVTLegalFeeSub.Enabled = false;
            txtPVTInsYear1.Enabled = false;
            txtPVTDesYear1.Enabled = false;
            txtPVTInsYear2.Enabled = false;
            txtPVTDesYear2.Enabled = false;
            txtPVTInsYear3.Enabled = false;
            txtPVTDesYear3.Enabled = false;
            txtPVTInsThereAfter.Enabled = false;
            txtPVTDesThereAfter.Enabled = false;
            txtPVTMoreInfo.Enabled = false;
            chkPVTStatus.Enabled = false;

            rfvPVTMinLoanTenure.Enabled = false;
            rfvPVTMaxLoanTenure.Enabled = false;
            rfvPVTMinAgeOfApplicant.Enabled = false;
            rfvPVTMaxAgeOfApplicant.Enabled = false;
            rfvPVTMaxMarginFin.Enabled = false;
            rfvPVTInsYear1.Enabled = false;
            revPVTInsYear1.Enabled = false;
            rfvPVTInsYear2.Enabled = false;
            revPVTInsYear2.Enabled = false;
            rfvPVTInsYear3.Enabled = false;
            revPVTInsYear3.Enabled = false;
            rfvPVTInsThereAfter.Enabled = false;
            revPVTInsThereAfter.Enabled = false;
        }
        if (chkHDB.Checked)
        {
            ddlHDBMinLoanTenure.Enabled = true;
            ddlHDBMaxLoanTenure.Enabled = true;
            ddlHDBMinAgeOfApplicant.Enabled = true;
            ddlHDBMaxAgeOfApplicant.Enabled = true;
            ddlHDBMaxMarginFin.Enabled = true;
            txtHDBFullRedPen.Enabled = true;
            txtHDBLegalFeeSub.Enabled = true;
            txtHDBInsYear1.Enabled = true;
            txtHDBDesYear1.Enabled = true;
            txtHDBInsYear2.Enabled = true;
            txtHDBDesYear2.Enabled = true;
            txtHDBInsYear3.Enabled = true;
            txtHDBDesYear3.Enabled = true;
            txtHDBInsThereAfter.Enabled = true;
            txtHDBDesThereAfter.Enabled = true;
            txtHDBMoreInfo.Enabled = true;
            chkHDBStatus.Enabled = true;

            rfvHDBMinLoanTenure.Enabled = true;
            rfvHDBMaxLoanTenure.Enabled = true;
            rfvHDBMinAgeOfApplicant.Enabled = true;
            rfvHDBMaxAgeOfApplicant.Enabled = true;
            rfvHDBMaxMarginFin.Enabled = true;
            rfvHDBInsYear1.Enabled = true;
            revHDBInsYear1.Enabled = true;
            rfvHDBInsYear2.Enabled = true;
            revHDBInsYear2.Enabled = true;
            rfvHDBInsYear3.Enabled = true;
            revHDBInsYear3.Enabled = true;
            rfvHDBInsThereAfter.Enabled = true;
            revHDBInsThereAfter.Enabled = true;
        }
        else
        {
            ddlHDBMinLoanTenure.Enabled = false;
            ddlHDBMaxLoanTenure.Enabled = false;
            ddlHDBMinAgeOfApplicant.Enabled = false;
            ddlHDBMaxAgeOfApplicant.Enabled = false;
            ddlHDBMaxMarginFin.Enabled = false;
            txtHDBFullRedPen.Enabled = false;
            txtHDBLegalFeeSub.Enabled = false;
            txtHDBInsYear1.Enabled = false;
            txtHDBDesYear1.Enabled = false;
            txtHDBInsYear2.Enabled = false;
            txtHDBDesYear2.Enabled = false;
            txtHDBInsYear3.Enabled = false;
            txtHDBDesYear3.Enabled = false;
            txtHDBInsThereAfter.Enabled = false;
            txtHDBDesThereAfter.Enabled = false;
            txtHDBMoreInfo.Enabled = false;
            chkHDBStatus.Enabled = false;

            rfvHDBMinLoanTenure.Enabled = false;
            rfvHDBMaxLoanTenure.Enabled = false;
            rfvHDBMinAgeOfApplicant.Enabled = false;
            rfvHDBMaxAgeOfApplicant.Enabled = false;
            rfvHDBMaxMarginFin.Enabled = false;
            rfvHDBInsYear1.Enabled = false;
            revHDBInsYear1.Enabled = false;
            rfvHDBInsYear2.Enabled = false;
            revHDBInsYear2.Enabled = false;
            rfvHDBInsYear3.Enabled = false;
            revHDBInsYear3.Enabled = false;
            rfvHDBInsThereAfter.Enabled = false;
            revHDBInsThereAfter.Enabled = false;
        }
    }

    //private void PanelVisible()
    //{
    //    if (ddlLockin.SelectedIndex == 2)
    //    {
    //        pnlLockin.Visible = true;
    //    }
    //    else
    //    {
    //        pnlLockin.Visible = false;
    //    }
    //}

    private void ShowHFVariables()
    {
        try
        {
            if (lblPackageId.Text != string.Empty)
            {
                Int64 _hfpackageid = Convert.ToInt64(lblPackageId.Text);
                HFVariableDetails _hfvariabledetails = new HFVariableDetails();
                HFVariableDetailsDB _hfvariabledetailsdb = new HFVariableDetailsDB();
                _hfvariabledetails = _hfvariabledetailsdb.GetVariableDetails(_hfpackageid);
                if (_hfvariabledetails != null)
                {
                    
                    ddlProviderName.Text = _hfvariabledetails.HFProviderId.ToString();
                    txtProductName.Text = _hfvariabledetails.ProductName;
                    ddlLoanPurpose.Text = _hfvariabledetails.LoanPurpose.ToString();
                    ddlPropertyStatus.Text = _hfvariabledetails.PropertyStatus.ToString();
                    ddlInterestRatePackage.Text = _hfvariabledetails.InterestRateType.ToString();
                    chkYes.Checked = _hfvariabledetails.HasMinimumLoanAmount;
                    if (chkYes.Checked)
                    {
                        txtMinimumAmount.Text = _hfvariabledetails.MinimumLoanAmount.ToString();
                    }
                    chkPolicyPeriod.Checked = _hfvariabledetails.HasPolicyPeriod;
                    ddlLockin.Text = _hfvariabledetails.LockIn.ToString();
                    //PanelVisible();
                    if (_hfvariabledetails.PVTPropertyType == 1)
                    {
                        chkPrivate.Checked = true;
                        chkPrivate.Enabled = false;
                        txtPropertyType.Text = "1";
                        lblPVTHFID.Text = _hfvariabledetails.PVTHFVariableId.ToString();
                        ddlPVTMinLoanTenure.Text = Convert.ToString(_hfvariabledetails.PVTMinLoanTenure);
                        ddlPVTMaxLoanTenure.Text = Convert.ToString(_hfvariabledetails.PVTMaxLoanTenure);
                        ddlPVTMinAgeOfApplicant.Text = Convert.ToString(_hfvariabledetails.PVTMinAgeApplicant);
                        ddlPVTMaxAgeOfApplicant.Text = Convert.ToString(_hfvariabledetails.PVTMaxAgeApplicant);
                        ddlPVTMaxMarginFin.Text = Convert.ToString(_hfvariabledetails.PVTMaxMarginFin);
                        txtPVTFullRedPen.Text = _hfvariabledetails.PVTFullRedPen;
                        txtPVTLegalFeeSub.Text = _hfvariabledetails.PVTLegalFeeSubsidy;
                        txtPVTInsYear1.Text = Convert.ToString(_hfvariabledetails.PVTInterestY1);
                        txtPVTDesYear1.Text = _hfvariabledetails.PVTDescriptionY1;
                        txtPVTInsYear2.Text = Convert.ToString(_hfvariabledetails.PVTInterestY2);
                        txtPVTDesYear1.Text = _hfvariabledetails.PVTDescriptionY1;
                        txtPVTInsYear3.Text = Convert.ToString(_hfvariabledetails.PVTInterestY3);
                        txtPVTDesYear1.Text = _hfvariabledetails.PVTDescriptionY1;
                        txtPVTInsThereAfter.Text = Convert.ToString(_hfvariabledetails.PVTInterestThereAfter);
                        txtPVTDesThereAfter.Text = _hfvariabledetails.PVTDescriptionThereAfter;
                        txtPVTMoreInfo.Text = _hfvariabledetails.PVTMoreInfo;
                        chkPVTStatus.Checked = _hfvariabledetails.PVTStatus;
                    }
                    if (_hfvariabledetails.HDBPropertyType == 2)
                    {
                        chkHDB.Checked = true;
                        chkHDB.Enabled = false;
                        txtPropertyType.Text = "1";
                        lblHDBHFID.Text = _hfvariabledetails.HDBHFVariableId.ToString();
                        ddlHDBMinLoanTenure.Text = Convert.ToString(_hfvariabledetails.HDBMinLoanTenure);
                        ddlHDBMaxLoanTenure.Text = Convert.ToString(_hfvariabledetails.HDBMaxLoanTenure);
                        ddlHDBMinAgeOfApplicant.Text = Convert.ToString(_hfvariabledetails.HDBMinAgeApplicant);
                        ddlHDBMaxAgeOfApplicant.Text = Convert.ToString(_hfvariabledetails.HDBMaxAgeApplicant);
                        ddlHDBMaxMarginFin.Text = Convert.ToString(_hfvariabledetails.HDBMaxMarginFin);
                        txtHDBFullRedPen.Text = _hfvariabledetails.HDBFullRedPen;
                        txtHDBLegalFeeSub.Text = _hfvariabledetails.HDBLegalFeeSubsidy;
                        txtHDBInsYear1.Text = Convert.ToString(_hfvariabledetails.HDBInterestY1);
                        txtHDBDesYear1.Text = _hfvariabledetails.HDBDescriptionY1;
                        txtHDBInsYear2.Text = Convert.ToString(_hfvariabledetails.HDBInterestY2);
                        txtHDBDesYear1.Text = _hfvariabledetails.HDBDescriptionY1;
                        txtHDBInsYear3.Text = Convert.ToString(_hfvariabledetails.HDBInterestY3);
                        txtHDBDesYear1.Text = _hfvariabledetails.HDBDescriptionY1;
                        txtHDBInsThereAfter.Text = Convert.ToString(_hfvariabledetails.HDBInterestThereAfter);
                        txtHDBDesThereAfter.Text = _hfvariabledetails.HDBDescriptionThereAfter;
                        txtHDBMoreInfo.Text = _hfvariabledetails.HDBMoreInfo;
                        chkHDBStatus.Checked = _hfvariabledetails.HDBStatus;
                    }
                    EnableDisable();
                    if (chkPolicyPeriod.Checked)
                    {
                        pnlPolicyPeriod.Visible = true;
                        ddlPolicyFrom.Day = _hfvariabledetails.PolicyPeriodFrom.Day;
                        ddlPolicyFrom.Month = _hfvariabledetails.PolicyPeriodFrom.Month;
                        ddlPolicyFrom.Year = _hfvariabledetails.PolicyPeriodFrom.Year;

                        ddlPolicyTo.Day = _hfvariabledetails.PolicyPeriodTo.Day;
                        ddlPolicyTo.Month = _hfvariabledetails.PolicyPeriodTo.Month;
                        ddlPolicyTo.Year = _hfvariabledetails.PolicyPeriodTo.Year;
                    }
                }
                else
                {
                    ClearFields();
                }

                _hfvariabledetails = null;
                _hfvariabledetailsdb = null;
            }
        }
        catch (Exception Ex)
        {

        }
    }
}
